<template>
  <section class="webview fixHeight">
    <el-scrollbar style="height:100%">
      <div class="search">
        <div class="content">
          <div class="part1">
            <div class="item">
              <span class="name">关键字</span>
              <el-input
                v-model="detail.title"
                class="input margin-left"
                placeholder="关键字"
                maxlength="20"
                @keyup.enter.native="search"
              />
            </div>
			<div class="item">
			  <span class="name">状态</span>
			  <el-select v-model="detail.status" class="input margin-left" placeholder="请选择">
			    <el-option
			      v-for="item in statustype"
			      :key="item.value"
			      :label="item.label"
			      :value="item.value"
			    />
			  </el-select>
			</div>
<!--            <div class="item">-->
<!--              <span class="name">房屋类型</span>-->
<!--              <el-select v-model="detail.newOrSecond" class="input margin-left" placeholder="请选择">-->
<!--                <el-option-->
<!--                  v-for="item in typeOptions"-->
<!--                  :key="item.value"-->
<!--                  :label="item.label"-->
<!--                  :value="item.value"-->
<!--                />-->
<!--              </el-select>-->
<!--            </div>-->
            <div class="searchItem">
              <el-button type="success" round class="search-btn" @click="getList">搜索</el-button>
            </div>
          </div>
        </div>
      </div>
      <div class="table margin-top padding-bottom">
        <el-table
          ref="multipleTable"
          empty-text="暂无数据"
          :data="list"
          style="width: 100%"
          :row-style="{background: '#FCFDFF'}"
          :header-cell-style="{background:'#46705D',color:'#ffffff'}"
          @select-all="handleSelectAll"
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            type="selection"
            width="55"
          />
          <el-table-column fixed type="index" label="序号" :show-overflow-tooltip="true" align="center" />
         
         <el-table-column label="头像" :show-overflow-tooltip="true" align="center">
            <template slot-scope="scope">
             <img style="display: block;width: 80px;height: 80px;margin: auto;" :src="scope.row.headPortrait" alt="">
            </template>
          </el-table-column>
          <el-table-column label="姓名" :show-overflow-tooltip="true" align="center">
            <template slot-scope="scope">
              <div>{{ scope.row.name }}</div>
            </template>
          </el-table-column>
          <el-table-column label="手机" :show-overflow-tooltip="true" align="center">
            <template slot-scope="scope">
              <div>{{ scope.row.phone}}</div>
            </template>
          </el-table-column>
          <el-table-column label="等级" :show-overflow-tooltip="true" align="center">
            <template slot-scope="scope">
              <div v-if="scope.row.level==1">初级</div>
              <div v-if="scope.row.level==2">中级</div>
              <div v-if="scope.row.level==3">高级</div>
            </template>
          </el-table-column>
          <el-table-column label="所属公司" :show-overflow-tooltip="true" align="center">
            <template slot-scope="scope">
              <div>{{ scope.row.enterpriseName }}</div>
            </template>
          </el-table-column>
          
          <el-table-column label="状态" :show-overflow-tooltip="true" align="center">
            <template slot-scope="scope">
              <div>{{  scope.row.status }}</div>
            </template>
          </el-table-column>
		  
          <el-table-column fixed="right" label="操作" :show-overflow-tooltip="true" align="center" width="250">
            <template slot-scope="scope">
              <el-button type="text" size="small"  @click="toSee(scope.row)">查看</el-button>
              <el-button type="text" size="small" @click="ok(scope.row.id)">通过</el-button>
              <el-button type="text" size="small" @click="back(scope.row.id)">打回</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="pageContain margin-top">
          <div style="flex: 1;text-align: right;">共{{pagination.total}}条</div>
          <el-pagination
            :current-page="pagination.page"
            :page-size="pagination.pageSize"
            :background="true"
            layout="prev, pager, next"
            :total="pagination.total"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </el-scrollbar>
  </section>
</template>
<script>
import { aagentList,agentDelete,agentUpdateStatus } from '@/api/api'
export default {
  data() {
    return {
      list: [],
      pagination: {
        pageSize: 10,
        page: 1,
        total: 0
      },
      detail: {
        title: '',
        templateType: ''
      },
	  statustype: [
	  {
	    value: 0,
	    label: '已通过'
	  },
	  {
	    value: 4,
	    label: '未通过'
	  }],
      typeOptions: [
        {
          value: 1,
          label: '新房'
        },
        {
          value: 2,
          label: '二手房'
        }],
      ids: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
	  ok(id){
	  		  agentUpdateStatus({
	  		    id: id,
	  		    status: 0,
				type:4
	  		  }).then(data => {
	  		    Is.tip('设置成功')
	  		    this.getList()
	  		  })
	  },
	  back(id){
		  this.$prompt('请输入打回理由', '提示', {
		            confirmButtonText: '确定',
		            cancelButtonText: '取消'
		          }).then(({ value }) => {
					  agentUpdateStatus({
					    id: id,
					    status:4,
						remark:value,
						type:4
					  }).then(data => {
					    Is.tip('设置成功')
					    this.getList()
					  })
		          }).catch(() => {
		                 
		          });
	  		 
	  },
    
    toSee(item) {
      this.$router.push({ path: '/examine/see', query: { data: JSON.stringify(item),type:4 }})
    },
    editStatusSingle(type, id) {
      if (type == 1) {
        // 启用
        updateHospitalStatus({
          ids: [id],
          status: 1
        }).then(data => {
          Is.tip('启用成功')
          this.getList()
        })
      }
    },
	
    editStatusSingles(type) {
      if (Is.empty(this.ids)) {
        Is.tip('未选择编辑项')
        return false
      }
      if (type == 1) {
        // 启用
        updateHospitalStatus({
          ids: this.ids,
          status: 1
        }).then(data => {
          Is.tip('启用成功')
          this.getList()
        })
      }
      if (type == 0) {
        // 禁用
        updateHospitalStatus({
          ids: this.ids,
          status: 0
        }).then(data => {
          Is.tip('禁用成功')
          this.getList()
        })
      }
    },
    reset() {
      this.detail = {
        title: ''
      }
      this.pagination = {
        pageSize: 10,
        page: 1,
        total: 0
      }
      this.getList()
    },
    getList() {
		
      const params = {
        curPage: this.pagination.page,
        pageSize: this.pagination.pageSize,
		name:this.detail.title,
		status:this.detail.status,
		type:4
      }
      aagentList(params).then(data => {
		  this.list = data.data.records
		  this.pagination.total = data.data.total
		  
		for(var i=0;i<data.data.records.length;i++){
			switch (data.data.records[i].status) {
			  case 0:
			     this.list[i].status = '已通过'
			    break
			  case 1:
			     this.list[i].status = '禁用'
			    break
			  case 2:
			     this.list[i].status = '冻结'
			    break
			  case 3:
			     this.list[i].status = '待审核'
			    break
			  case 4:
			     this.list[i].status = '未通过'
			    break
			}
		};
		
      })
    },
    handleSelectAll(selection) {
      this.ids = []
      if (selection.length > 0) {
        selection.forEach(item => {
          this.ids.push(item.id)
        })
      }
    },
    handleCurrentChange(val) {
      // 重置当前页码
      this.pagination.page = val
      this.getList()
    },
    handleSelectionChange(selection) {
      this.ids = []
      if (selection.length > 0) {
        selection.forEach(item => {
          this.ids.push(item.id)
        })
      }
    }
  }}
</script>
